package com.timmy.smarttest.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.inuker.bluetooth.library.search.SearchResult;
import com.timmy.smarttest.R;
import com.timmy.smarttest.utis.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: Timmy
 * @Data: 2017/7/4
 * @Fuction:
 */

public class ResultsAdapter extends BaseAdapter {

    private Context mContext;
    private List<SearchResult> mResults;

    public ResultsAdapter(Context context) {
        mContext = context;
        mResults = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return mResults.size();
    }

    @Override
    public Object getItem(int position) {
        return mResults.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setData(List<SearchResult> results) {
        mResults = results;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        BaseViewHolder holder = BaseViewHolder.getViewHolder(mContext, convertView, parent, R.layout.item_device_list, position);
        TextView tvName = holder.getView(R.id.tv_name);
        SearchResult searchResult = mResults.get(position);
        tvName.setText(searchResult.getName());

        return holder.getConvertView();
    }

    public void addData(SearchResult item) {
        mResults.add(item);
        notifyDataSetChanged();
    }
}
